<template>
  <Dialog
    v-model="show"
    @confirm="handleSubmit"
    @close="close"
    title="新增消息"
    width="600px"
  >
    <el-form :model="formData" label-width="120px" ref="formRef" :rules="rules">
      <el-form-item label="年费金额" prop="name">
        <el-input v-model="formData.name" />
      </el-form-item>
    </el-form>
  </Dialog>
</template>
<script setup>
import { ref, watch } from "vue";
import Dialog from "@/components/dialog.vue";
const show = defineModel();
const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
  },
});
watch(show, (val) => {
  if (val) {
    props.data && (formData.value = props.data);
  }
});
const formData = ref({
  price: "",
});
const rules = ref({
  price: [{ required: true, message: "请输入年费金额", trigger: "blur" }],
});
const formRef = ref();
const handleSubmit = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!");
    }
  });
};
const close = () => {
  formData.value.price = "";
  show.value = false;
};
</script>
